<php>
$this->display(tpl('head',true)); 
</php>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
	<legend>专题"{{$special['name'] }}"的评论</legend>
</fieldset>
<style>
	.table {
		background-color: #f8f8f8;
		padding: 20px;
	}
	
	.layui-table thead tr {
		background-color: #fff;
	}
	
	.layui-table thead tr th {
		font-weight: bold;
		text-align: center;
	}
	
	.layui-row {
		margin-bottom: 10px;
		margin-left: 20px;
	}
</style>
<div class="layui-row">
	<a class="layui-btn layui-btn-sm  layui-btn-warm" href="{{ADMIN_MODULE_URL  }}special/comment/id_{{$_GET['id'] }}/state_0">未审</a>
	<a class="layui-btn layui-btn-sm  layui-btn-danger" href="{{ ADMIN_MODULE_URL  }}special/comment/id_{{$_GET['id'] }}/state_1">已审</a>
	<a class="layui-btn layui-btn-sm" href="{{ ADMIN_MODULE_URL  }}special/comment/id_{{$_GET['id'] }}/">全部</a>
</div>
<form class="layui-form" id="from" method="post" action="">
	<table class="layui-table">
		<thead>
			<tr>
				<th width="20" align="right"></th>
				<th width="50">Id</th>
				<th>评论内容</th>
				<th width="50">发布人</th>
				<th width="60">发布时间</th>
				<th width="60">状态</th>
				<th width="40">操作</th>
			</tr>
		</thead>
		<tbody id="tbody">
			<foreach array="data">
			<php>	$state=$row['state']===1 ? "checked" : "";</php>
				<tr id="list_{{$row['id'] }}">
					<td align="right"><input name="iddb[]" value="{{$row['id'] }}" class="dr_select" lay-skin="primary" type="checkbox"></td>
					<td align="center">
						{{$row['id'] }}
					</td>
					<td>
						{{$row['content'] }}
					</td>
					<td align="center">
						{{$row['username'] }}
					</td>
					<td align="center">
						{{date('Y-m-d H:i:s',$row['posttime'])  }}
					</td>
					<td>
						<div class="layui-form-item">
							<div class="layui-input-block">
								<input {{$state }} lay-skin="switch" lay-filter="state" id="{{$row['id'] }}" lay-text="已审|待审" type="checkbox" value="1">
							</div>
						</div>
					</td>
					<td class="dr_option">
						<button class="layui-btn layui-btn-sm"  onclick="return del('{{$row['id'] }}')">删除</button>
					</td>
				</tr>
			</foreach>
				<if condition="!$data">
					<tr>
						<td colspan="7" align="center">暂无评论......</td>
					</tr>
				</if>
		</tbody>
	</table>
	<div class="button">
		<input type="hidden" id="step" name="step"  />
		<button class="layui-btn layui-btn-sm layui-btn-warm" onclick="return all_checkbox_check('1')">全选</button>
		<button class="layui-btn layui-btn-sm layui-btn-warm" onclick="return all_checkbox_check('-1')">反选</button>
		<button class="layui-btn layui-btn-sm layui-btn-warm" onclick="return all_checkbox_check('0')">取消选择</button>
		<button class="layui-btn layui-btn-sm layui-btn-danger" name="state" value="1" onclick="return post('state')">通过审核</button>
		<button class="layui-btn layui-btn-sm layui-btn-danger" name="state" value="0" onclick="return post('state')">取消审核</button>
		<button class="layui-btn layui-btn-sm layui-btn-danger" name="step" value="del" onclick="return post('del')">批量删除</button>
	</div>
	<div class="page">
		{{$Get_Page }}
	</div>
</form>

<script>
	function del(id){
		$.ajax({
			url: "{{ADMIN_MODULE_URL  }}special/comment_action/",
			type: 'POST',
			data: {
				'step':'del',
				'id': id
			},
			dataType: 'json',
			success: function(data) {
				if(data.code==1){
					$('#list_'+id).remove();
				}else{
					alert(data.text);
				}
			}
		});
		return false;
	}
	function all_checkbox_check(type) {
		if(document.getElementsByClassName('layui-form-checkbox') != undefined && document.getElementsByClassName('layui-form-checkbox').length > 0) {
			var class_box = document.getElementsByClassName('layui-form-checkbox');
			var ids = document.getElementsByName('iddb[]');
			if(type == "1") { //全选
				for(var i = 0; i < class_box.length; i++) {
					$(ids[i]).prop("checked", true);
					$(class_box[i]).addClass("layui-form-checked");
				}
			} else if(type == "0") { //全不选
				for(var i = 0; i < class_box.length; i++) {
					$(ids[i]).prop("checked", false);
					$(class_box[i]).removeClass("layui-form-checked");
				}
			} else if(type == "-1") { //反选
				for(var i = 0; i < class_box.length; i++) {
					if(ids[i].checked == true) {
						$(ids[i]).prop("checked", false);
					} else {
						$(ids[i]).prop("checked", true);
					}
					$(class_box[i]).toggleClass("layui-form-checked");
				}
			}
		}
		return false;
	}

	function post(a) {
		if(a === 'state') {
			$('#step').val('state');
			$('#from').attr('action', '{{ ADMIN_MODULE_URL  }}special/comment_action/');
		} else {
			$('#step').val('del');
			$('#from').attr('action', '{{ ADMIN_MODULE_URL  }}special/comment_action/');
		}
	}

	layui.use(['form', 'layer'], function() {
		var form = layui.form,
			layer = layui.layer;

		form.on('switch(state)', function(obj) {
			if(obj.elem.checked == true) {
				var state = 1;
			} else {
				var state = 0;
			}
			$.ajax({
				url: "{{ADMIN_MODULE_URL }}special/comment_action/",
				type: 'POST',
				data: {
					'step':'state',
					'state': state,
					'id': obj.elem.id
				},
				dataType: 'json',
				success: function(data) {
					if(obj.elem.checked == true) {
						layer.tips("已完成审核", obj.othis);
					} else {
						layer.tips("已取消审核", obj.othis);
					}
				}
			})
		});
	});
</script>

<php>
$this->display(tpl('foot',true)); 
</php>
